import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PrismaModule } from './prisma/prisma.module';
import { UserModule } from './user/user.module';
import { RedisModule } from './redis/redis.module';
import { EmailModule } from './email/email.module';
import { JwtModule } from "@nestjs/jwt";
import { AuthGuard } from "./auth.guard";
import { APP_GUARD } from '@nestjs/core';
import { FriendshipModule } from './friendship/friendship.module';
import { ChatroomModule } from './chatroom/chatroom.module';
import { ChatModule } from './chat/chat.module';
import { ChatHistoryModule } from './chat-history/chat-history.module';
import { FavoriteModule } from './favorite/favorite.module';

@Module({
  imports: [
    PrismaModule,
    UserModule,
    RedisModule,
    EmailModule,
    // 这里用到了动态Module和动态Provider的知识
    JwtModule.registerAsync({
      global: true,
      useFactory() {
        // 动态模块的返回值就是其对外提供的服务
        return {
          secret: 'wyt',
          signOptions: {
            expiresIn: '30m' // 如果生成token时没有传，token失效时间默认30分钟
          }
        }
      },
    }),
    FriendshipModule,
    ChatroomModule,
    ChatModule,
    ChatHistoryModule,
    FavoriteModule
  ],
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: APP_GUARD,
      useClass: AuthGuard
    }
  ],
})
export class AppModule { }
